package com.april.controller;

import com.april.pojo.TbItem;
import com.april.service.ItemService;
import com.april.utils.PageResult;
import com.april.utils.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: 槐序 廿一
 * @Date: 2023-06-19
 * @Time: 17:36
 * @Description:
 */
@RestController
@RequestMapping("item")
public class ItemController {

    @Resource
    ItemService itemService;

    @RequestMapping("provider/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(@RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                            @RequestParam(value = "rows", defaultValue = "10", required = false) int rows) {
        return itemService.findItemByPage(page, rows);
    }

    @RequestMapping("provider/insertTbItem")
    int insertTbItem(@RequestBody TbItem tbItem,
                     @RequestParam(value = "desc") String desc,
                     @RequestParam(value = "itemParams") String itemParams) {
        return itemService.insertTbItem(tbItem, desc, itemParams);
    }

    @RequestMapping("provider/preUpdateItem")
    Map<String, Object> preUpdateItem(@RequestParam(value = "itemId") Long itemId) {
        return itemService.preUpdateItem(itemId);
    }

    @RequestMapping("provider/updateTbItem")
    int updateTbItem(@RequestBody TbItem tbItem,
                     @RequestParam(value = "desc") String desc,
                     @RequestParam(value = "itemParams") String itemParams) {
        return itemService.updateTbItem(tbItem, desc, itemParams);
    }
}
